package com.ymttest.business.service;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.http.client.ClientProtocolException;

import com.ymatou.iapi.deviceid.parameter.SaveBean;
import com.ymatou.iapi.deviceid.service.SaveCall;
import com.ymttest.utils.TestDataManager;

public class DeviceidCallService {
	
	public static SaveBean setDefaultSaveBean()
	{
		String num = TestDataManager.getRandomNum(10);
		
		SaveBean saveBean = new SaveBean();
		saveBean.setAppid("1");
		saveBean.setDeviceid(num);
		saveBean.setClienttype(1);
		
		return saveBean;
	}
	
	public static SaveBean setDefaultFullSaveBean()
	{
		String num = TestDataManager.getRandomNum(10);
		
		SaveBean saveBean = new SaveBean();
		saveBean.setAppid("1");
		saveBean.setDeviceid(num);
		saveBean.setClienttype(1);
		saveBean.setAppversion("1");
		saveBean.setPackageid("10");
		saveBean.setIp(TestDataManager.getRandomIp());
		saveBean.setUserid(Integer.parseInt(TestDataManager.getRandomNum(8)));
		saveBean.setCcid(TestDataManager.getRandomNum(8));
		saveBean.setCkid(TestDataManager.getRandomNum(8));
		saveBean.setOsversion("ios10.0");
		//saveBean.setSign(TestDataManager.getRandomNum(15));
		saveBean.setNetwork("YCP/IP");
		saveBean.setYid(TestDataManager.getRandomNum(8));
		saveBean.setDid(TestDataManager.getRandomNum(8));
		saveBean.setIsupdate(true);
		saveBean.setPower("80");
		saveBean.setAppkey("ios");
		
		SimpleDateFormat sdf = new SimpleDateFormat(
				"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
		Date date = new Date();
		
		saveBean.setTimestamp(sdf.format(date));
		saveBean.setAcceptversion("123");
		saveBean.setMac(TestDataManager.getRandomNum(5));
		
		/**
		 * 是否验证md5通过（1：没验证 2：通过 3：失败）
		 */
		saveBean.setSignVerified(2);
		saveBean.setAppname("yamtou.app");
		return saveBean;
	}
	
	public static SaveCall saveCall(SaveBean saveBean) throws ClientProtocolException, IOException{
		 SaveCall saveCall = new SaveCall();
		 
		 saveCall.setData(false,saveBean);
		 saveCall.callService();
		 
		 return saveCall;
	}

}
